﻿using Ruici.Web.Services;
using Ruici.Web.Services.CRS_Service;
using Ruici.Web.Services.Model;
using System;
using System.Collections.Generic;

namespace Ruici.BLL
{
    public class OrderBll
    {
        private UserReservitionService userService = new UserReservitionService();
        private OrderService _orderservice;
        private DocInfoService _docInfoService;
        public OrderBll()
        {
            _orderservice = new OrderService();
            _docInfoService = new DocInfoService();
        }

        /// <summary>
        /// 创建预约意向单
        /// </summary>
        /// <param name="pid">就诊人PID （如果没有，传0，但此时必须传一个正确的userInfoJson；否则userInfoJson应传空）</param>
        /// <param name="type">预约类型 普通预约 = 0；加号预约 = 1；点诊 = 2;</param>
        /// <param name="hospId">医院Id</param>
        /// <param name="remoteHospId">医生出诊医院Id 可以判断是否是远程就诊</param>
        /// <param name="depId">门诊Id</param>
        /// <param name="depTypeId">门诊类型Id</param>
        /// <param name="doctorId">医生Id</param>
        /// <param name="timePeriod">预约时间段 使用从接口中取到的开始结束时间，用-连接，如：9:00-10:00</param>
        /// <param name="resvDate">预约日期</param>
        /// <param name="description">客人主诉</param>
        /// <param name="pictures">客户上传的描述图片 多张的话逗号隔开</param>
        /// <param name="userIP">用户下单时候的IP</param>
        /// <param name="platform">平台 Android APP/iOS/微信/Web</param>
        /// <param name="OpenId"></param>
        /// <param name="userInfoJson">用户信息JSON 包括Name(string)，Mobile(string)，Sex(string)，CertNo(string)，Birthday(DateTime?)</param>
        /// <param name="operatorPid">预约操作人PID 当前登陆人的PID（APP没有PID的话传0）</param>
        /// <returns>Data 预约单号</returns>
        public ReturnModelOfString ResvIntentionAdd(int pid,
                    int type,
                    int hospId,
                    int remoteHospId,
                    int depId,
                    int depTypeId,
                    int doctorId,
                    string timePeriod,
                    System.DateTime resvDate,
                    string description,
                    string pictures,
                    string userIP,
                    string platform,
                    string OpenId,
                    string userInfoJson,
                    int operatorPid)
        {
            var resvReturnId = _orderservice.ResvIntentionAdd(pid, type, hospId, remoteHospId, depId, depTypeId, doctorId, timePeriod, resvDate, description, pictures, userIP, platform, OpenId, userInfoJson, operatorPid);

            return resvReturnId;
        }

        /// <summary>
        /// 获取用户的预约列表
        /// </summary>
        /// <param name="Pid">用户PID</param>
        /// <returns>resvIntention列表</returns>
        public List<resvIntention> getResvIntentionList(int Pid)
        {
            List<resvIntention> resvIntentionList = userService.ResvIntention_GetList(Pid);

            return resvIntentionList;
        }

        /// <summary>
        /// 取消预约（预约意向单）
        /// </summary>
        /// <param name="resvId">预约单Id</param>
        /// <returns></returns>
        public bool ResvIntentionCancle(int resvId)
        {
            return _orderservice.ResvIntentionCancle(resvId);
        }

        /// <summary>
        /// 删除预约（预约意向单）
        /// </summary>
        /// <param name="resvId">预约单Id</param>
        /// <returns></returns>
        public bool ResvIntentionDelete(int resvId)
        {
            return _orderservice.ResvIntentionDelete(resvId);
        }

        /// <summary>
        /// 根据门诊类别ID获取门诊信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ClinicCategoryInfoResponse GetClinicCategory(int id)
        {
            var clinicCategory = _orderservice.GetClinicCategory(id);
            return clinicCategory;
        }

        /// <summary>
        /// 获取城市列表
        /// </summary>
        /// <returns></returns>
        public List<CityModel> GetCityList()
        {
            return _orderservice.GetCityList();
        }

        /// <summary>
        /// 诊所列表信息
        /// </summary>
        /// <param name="cityId">城市code</param>
        /// <param name="keyword">查找条件</param>
        /// <param name="page">当前页</param>
        /// <param name="pageSize">页数</param>
        /// <returns></returns>
        public List<OrganizationModel> GetOrganizationList(string keyword, int page, int pageSize, int cityId)
        {
            var organizationList = _orderservice.GetOrganizationList(keyword, page, pageSize, cityId);
            return organizationList;
        }

        /// <summary>
        /// 获取就诊人列表
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public List<FamilyMemberListModel> GetFamilyMemberList(int pid)
        {
            var familyMembers = _orderservice.GetFamilyMemberList(pid);
            return familyMembers;
        }

        /// <summary>
        /// 添加就诊人（家庭成员）接口
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="name"></param>
        /// <param name="mobile"></param>
        /// <param name="IdCardNo"></param>
        /// <param name="isDefault"></param>
        /// <param name="relationship"></param>
        /// <param name="familyPid"></param>
        /// <param name="sex"></param>
        /// <param name="address"></param>
        /// <param name="birthday"></param>
        /// <returns></returns>
        public int FamilyMemberAdd(int pid, string name, string mobile, string IdCardNo, bool isDefault)
        {
            var familyMembers = _orderservice.FamilyMemberAdd(pid, name, mobile, IdCardNo, isDefault);
            return familyMembers;
        }

        /// <summary>
        /// 修改就诊人（家庭成员）接口
        /// </summary>
        /// <param name="id"></param>
        /// <param name="relationship">就诊人和自己的关系</param>
        /// <param name="name">就诊人姓名</param>
        /// <param name="mobile">就诊人手机号</param>
        /// <param name="address">就诊人住址</param>
        /// <param name="birthday">就诊人生日</param>
        /// <param name="sex">就诊人性别</param>
        /// <param name="IdCardNo">就诊人身份证号码</param>
        /// <param name="isDefault">是否是默认就诊人</param>
        /// <returns></returns>
        public FamilyMember FamilyMemberUpdate(int id, string relationship, string name, string mobile, string address, string sex, string IdCardNo, System.Nullable<bool> isDefault)
        {
            var familyMembers = _orderservice.FamilyMemberUpdate(id, relationship, name, mobile, address, sex, IdCardNo, isDefault);
            return familyMembers;
        }

        /// <summary>
        /// 删除指定ID的就诊人
        /// </summary>
        /// <param name="id">就诊人ID</param>
        /// <returns></returns>
        public bool FamilyMemberDelete(int id)
        {
            var familyMemberId = _orderservice.FamilyMemberDelete(id);
            return familyMemberId;
        }

        /// <summary>
        /// 设置指定的就诊人为默认就诊人
        /// </summary>
        /// <param name="id">就诊人ID</param>
        /// <returns></returns>
        public bool FamilyMemberSetDefault(int id)
        {
            var familyMemberId = _orderservice.FamilyMemberSetDefault(id);
            return familyMemberId;
        }


        /// <summary>
        /// 咨询预约图片保存
        /// </summary>
        /// <param name="pid">咨询用户PID</param>
        /// <param name="mediaIDs">保存的图片</param>
        /// <param name="subjectid">保存对象id</param>
        /// <param name="type">类型 1 咨询 2预约</param>
        /// <param name="platform">平台</param>
        /// <returns></returns>
        public bool addSeekDetail(int pid, string mediaIDs, string subjectid, int type, string platform)
        {
            var seekDetail = _orderservice.addSeekDetail(pid, mediaIDs, subjectid, type, platform);
            return seekDetail;
        }

        /// <summary>
        /// 医生是否远程
        /// </summary>
        /// <param name="docID"></param>
        /// <returns>0：线下 2：远程 1：线下远程</returns>
        public ReturnModel isRemote(int docID)
        {
            return _orderservice.isRemote(docID);
        }

        public List<Res_schedulingResponseBody> GetResSchedulingList(System.DateTime startime, System.DateTime endtime, string week, int mz_id, string mz_type_id, int doctored, int org_id)
        {
            var resSchedulingList = _orderservice.GetResSchedulingList(startime, endtime, week, mz_id, mz_type_id, doctored, org_id);
            return resSchedulingList;
        }

        public ReturnModelOfListOfDoctorSchedule GetDoctorScheduleBydocID(int docID)
        {
            var doctorSchedule = _docInfoService.GetDoctorScheduleBydocID(docID);
            return doctorSchedule;
        }

        public void ResvIntentionQuickAdd(string content)
        {
            _orderservice.SendMail(content);
        }

        public void SuggestQuickSend(string suggesttername, string suggesttermobile, string suggestcomments,  int pid)
        {
            _orderservice.SuggestQuickSend(suggesttername, suggesttermobile, suggestcomments,  pid);
        }
    }
}